<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class login extends CI_Controller {

    function __construct() {
        parent::__construct();

        $this->load->model('manage/m_login');
    }
 
    function index() {
        if (!IS_POST) {            
            $user = login_user();            
            if ($user) {
               show_jump('登录成功', site_url('manage/index/index'));
            }

            $data = array();
            $this->load->view('manage/login_form', $data);
        } else {
            $userinfo['admin_name'] = trim($this->input->post('admin_name'));
            $userinfo['admin_pwd'] = trim($this->input->post('admin_pwd'));

            if ($userinfo['admin_name'] == '') {
                show_jump('请输入账号', site_url('manage/login/index'));
            } elseif ($userinfo['admin_pwd'] == '') {
                show_jump('请输入密码', site_url('manage/login/index'));
            }
            $result = $this->m_login->check_user($userinfo);
            if ($result['error']) {
                show_jump($result['msg'], site_url('manage/login/index'));
            } else {
                
                session_start();
                
                $_SESSION['login_user'] = $result['user'];
                show_jump('登录成功', site_url('manage/index/index'));
                
            }
        }
      
    }
    
    function logout(){
        session_start(); 
        if($_SESSION['login_user']) unset ($_SESSION['login_user']);
        show_jump('已退出登录', base_url());
    }

}

?>